package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.SystemAreaEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 行政区划表Provider
 *
 * @author generator
 * @date 2020-05-18 10:52
 */
public class SystemAreaProvider {

    /**
     * 增加SystemArea
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-18 10:52
     */
    public String insertSystemArea(@Param("entity") SystemAreaEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" system_area ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" parent_id ", " #{entity.parentId,jdbcType=INTEGER} ");
                VALUES(" parent_code ", " #{entity.parentCode,jdbcType=VARCHAR} ");
                VALUES(" area_code ", " #{entity.areaCode,jdbcType=VARCHAR} ");
                VALUES(" area_name ", " #{entity.areaName,jdbcType=VARCHAR} ");
                VALUES(" area_name_abbr ", " #{entity.areaNameAbbr} ");

                if (entity.getDisableState() != null) {
                    VALUES(" disable_state ", " #{entity.disableState,jdbcType=TINYINT} ");
                }


                if (entity.getAsProvinceCityCounty() != null) {
                    VALUES(" as_province_city_county ", " #{entity.asProvinceCityCounty,jdbcType=TINYINT} ");
                }

                VALUES(" sort ", " #{entity.sort,jdbcType=INTEGER} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改SystemArea
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-18 10:52
     */
    public String updateSystemArea(@Param("entity") SystemAreaEntity entity) {
        return new SQL() {
            {
                UPDATE(" system_area ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" parent_id = #{entity.parentId,jdbcType=INTEGER} ");
                SET(" parent_code = #{entity.parentCode,jdbcType=VARCHAR} ");
                SET(" area_code = #{entity.areaCode,jdbcType=VARCHAR} ");
                SET(" area_name = #{entity.areaName,jdbcType=VARCHAR} ");
                SET(" area_name_abbr = #{entity.areaNameAbbr} ");

                if (entity.getDisableState() != null) {
                    SET(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }


                if (entity.getAsProvinceCityCounty() != null) {
                    SET(" as_province_city_county = #{entity.asProvinceCityCounty,jdbcType=TINYINT} ");
                }

                SET(" sort = #{entity.sort,jdbcType=INTEGER} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询SystemArea列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-18 10:52
     */
    public String listSystemArea(@Param("entity") SystemAreaEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,parent_id,parent_code,area_code,area_name,area_name_abbr,disable_state,as_province_city_county,sort,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" system_area ");

                if (entity.getParentId() != null) {
                    WHERE(" parent_id = #{entity.parentId,jdbcType=INTEGER} ");
                }

                if (entity.getParentCode() != null) {
                    WHERE(" parent_code = #{entity.parentCode,jdbcType=VARCHAR} ");
                }

                if (entity.getAreaCode() != null) {
                    WHERE(" area_code = #{entity.areaCode,jdbcType=VARCHAR} ");
                }

                if (entity.getAreaName() != null) {
                    WHERE(" area_name = #{entity.areaName,jdbcType=VARCHAR} ");
                }

                if (entity.getAreaNameAbbr() != null) {
                    WHERE(" area_name_abbr = #{entity.areaNameAbbr} ");
                }

                if (entity.getDisableState() != null) {
                    WHERE(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }

                if (entity.getAsProvinceCityCounty() != null) {
                    WHERE(" as_province_city_county = #{entity.asProvinceCityCounty,jdbcType=TINYINT} ");
                }

                if (entity.getSort() != null) {
                    WHERE(" sort = #{entity.sort,jdbcType=INTEGER} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}